package com.zide.platform.mapper;

import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.zide.auth.domain.entity.platform.dept.PlatformDept;
import com.zide.common.config.mybatisplus.ZiDeMapperPlus;
import com.zide.common.core.domain.PageResult;
import com.zide.platform.vo.search.dept.PlatformDeptSearchVO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;

import java.util.List;

/**
 * 参数配置 数据层
 *
 * @author zide
 */
@Mapper
public interface PlatformDeptMapper extends ZiDeMapperPlus<PlatformDept> {

    default PageResult<PlatformDept> selectPage(PlatformDeptSearchVO searchVO) {
        LambdaQueryWrapper<PlatformDept> wrapper = new LambdaQueryWrapper<>();
        if(ObjectUtil.isNotNull(searchVO.getId())) {
            wrapper.eq(PlatformDept::getId,searchVO.getId());
        }
        if(ObjectUtil.isNotNull(searchVO.getParentId())) {
            wrapper.eq(PlatformDept::getParentId,searchVO.getParentId());
        }
        if(StrUtil.isNotEmpty(searchVO.getDeptName())) {
            wrapper.like(PlatformDept::getDeptName,searchVO.getDeptName());
        }
        if(ObjectUtil.isNotNull(searchVO.getStatus())) {
            wrapper.eq(PlatformDept::getStatus,searchVO.getStatus());
        }
        wrapper.orderByAsc(PlatformDept::getParentId).orderByAsc(PlatformDept::getSorts);
        return selectPage(searchVO, wrapper);
    }

    List<Long> selectDeptListByRoleId(@Param("roleId") Long roleId,@Param("deptCheckStrictly")  boolean deptCheckStrictly);

    int selectNormalChildrenDeptById(Long deptId);

    int hasChildByDeptId(Long deptId);

    int checkDeptExistUser(Long deptId);

    PlatformDept checkDeptNameUnique(@Param("deptName") String deptName, @Param("parentId") Long parentId);

    int updateDeptStatusNormal(Long[] deptIds);

    List<PlatformDept> selectChildrenDeptById(Long deptId);

    int updateDeptChildren(List<PlatformDept> children);

}
